package 多线程;

/**
 * Created by Administrator on 2017/9/4.
 */
//线程的优先级无法保障线程的执行次序。只不过优先级高的线程获取 CPU 资源的概率大一点而已。
public class 多个线程顺序执行 {
    @SuppressWarnings("static-access")
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runner());
        Thread t2 = new Thread(new Runner());
        Thread t3 = new Thread(new Runner());
        t1.start();
        t1.sleep(1000); //让线程休眠，是为了更好的看到顺序效果
        t1.join(); //等待该线程终止

        t2.start();
        t2.sleep(1000);
        t2.join();
        t3.start();
        t3.join();
    }
}

class Runner implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"");
    }
}
